package_list <- c(
  "tidyverse", 
  "purrr",
  "haven", 
  "readxl", 
  "janitor", 
  "kableExtra", 
  "viridis", 
  "ggrepel", 
  "ggpattern",
  "modelsummary",
  "fixest",
  "modelr",
  "cowplot",
  "gridExtra",
  "grid"
)

new_packages <- package_list[!(package_list %in% installed.packages()[,"Package"])]
for (package in package_list) {
  if (package %in% new_packages) {
    install.packages(package, repos='http://cran.us.r-project.org')
    print(paste0("Installed ", package))
  } else {
    print(paste0(package, " already installed"))
  }
  library(package, character.only = T)
  print(paste0("Loaded ", package, " at version ",packageVersion(package)))
}
